package com.company.project.task;


import com.company.project.configurer.BeanContext;
import com.company.project.dao.OrderMainMapper;
import com.company.project.model.OrderMain;
import com.company.project.websocket.WebSocket;

public class ShopOrderReceive implements Runnable{

    private OrderMainMapper orderMainMapper;

    boolean stopMe = true;
    Integer shopId = 0;
    int oldPay = 0;
    int oldFin = 0;

    public void stopMe() {
        stopMe = false;
    }
    public void setShopId(String pageCode) {
        this.shopId = Integer.parseInt(pageCode);
    }

    @Override
    public void run() {
        this.orderMainMapper = BeanContext.getApplicationContext().getBean(OrderMainMapper.class);
        OrderMain query = new OrderMain();
        query.setShopId(this.shopId);
        query.setStatus(1);
        orderMainMapper.selectAll();
        oldPay = orderMainMapper.selectCount(query);
        query.setStatus(2);
        oldFin= orderMainMapper.selectCount(query);
        while(stopMe) {
            query.setStatus(1);
            int num1 = orderMainMapper.selectCount(query);
            query.setStatus(2);
            int num2 = orderMainMapper.selectCount(query);
            if(num1 == oldPay && num2 == oldFin + 1) {
                WebSocket webSocket = new WebSocket();
                webSocket.onMessage(this.shopId);
                oldPay = num1;
                oldFin = num2;
            }
        }
    }


}
